//package com.cactus.auth2.config;
//
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
//import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
//import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
//import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
//import org.springframework.security.oauth2.provider.ClientDetailsService;
//import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
//import org.springframework.security.oauth2.provider.token.TokenStore;
//import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
//
//import javax.sql.DataSource;
//
//@Configuration
//@EnableAuthorizationServer
//public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
//
//    /**
//     * 配置自定义数据源，覆盖spring security oauth2自带的
//     * @return
//     */
//    @Bean
//    @Primary //有多个配置实现时指定要使用的配置
//    @ConfigurationProperties(prefix = "spring.datasource") //指定自定义数据源
//    public DataSource dataSource(){
//        return DataSourceBuilder.create().build();
//    }
//
//    //给jdbc模式的TokenStore配置数据源处理token的存取
//    @Bean
//    public TokenStore jdbcTokenStore(){
//        return new JdbcTokenStore(dataSource());
//    }
//
//    //给jdbc模式的ClientDetailsService 服务配置数据源处理client相关信息的存取，需要数据库提前有值才可取出比对
//    @Bean
//    public ClientDetailsService jdbcClientDetailsService(){
//        return new JdbcClientDetailsService(dataSource());
//    }
//
//    //配置token的处理方式为jdbc模式
//    @Override
//    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
//        endpoints.tokenStore(jdbcTokenStore());
//    }
//
//    //配置client相关信息的处理方式为jdbc模式
//    @Override
//    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
//        clients.withClientDetails(jdbcClientDetailsService());
//    }
//}